package com.tudou.searchcontrol.filter;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.tudou.searchcontrol.common.Constants;

/**
 * 
 * @author zwu
 *
 */
public class LoginFilter implements Filter {

	public boolean preHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2) throws Exception {
		return false;
	}

	public void destroy() {

	}

	public void doFilter(ServletRequest req, ServletResponse response, FilterChain arg2) throws IOException, ServletException {

		HttpServletRequest httpRequest = (HttpServletRequest) req;
		HttpServletResponse httpResponse = (HttpServletResponse) response;
		String path = httpRequest.getServletPath();

//		if (path.indexOf("/login/") >= 0 || path.indexOf("/index.htm") >= 0) {
//			arg2.doFilter(req, response);
//			return;
//		}

//		UserInfo userInfo = (UserInfo)httpRequest.getSession().getAttribute(Constants.LOGIN_USERNAME);
//		if(userInfo == null){
//			httpResponse.sendRedirect(httpRequest.getContextPath()+"/index.htm");
//			return;
//		}
		

		arg2.doFilter(req, response);
	}

	public void init(FilterConfig arg0) throws ServletException {

	}
}
